#pragma once
#include "dxroids.h"

namespace dxroids
{
   class GameTime
   {

   public:

      int64_t Elapsed;

      GameTime();
      GameTime & operator = ( GameTime const & _rhs);
     
      float SecondsBetween(GameTime const & _rhs) const;

      static int64_t SecondsToTicks(float _seconds);
      static int64_t Now();
      static int64_t Frequency();
                  
   private:

      const int64_t frequency_;

   };
}



inline dxroids::GameTime & dxroids::GameTime::operator = (dxroids::GameTime const & _rhs)
{
   if (&_rhs != this)
   {
      Elapsed = _rhs.Elapsed;
   }
   return *this;
}

inline int64_t dxroids::GameTime::SecondsToTicks(float _seconds)
{
   return static_cast<int64_t>(::ceil(Frequency() * _seconds));
}

inline int64_t dxroids::GameTime::Now()
{
   int64_t count = 0;
   DxRoidsAssert( QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER *>(&count)) );
   return count;
}

inline int64_t dxroids::GameTime::Frequency()
{
   int64_t frequency = 0;
   DxRoidsAssert( QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER *>(&frequency)) );
   return frequency;
}
      
inline float dxroids::GameTime::SecondsBetween(GameTime const & _rhs) const
{
   DxRoidsAssert(_rhs.frequency_ == this->frequency_);
   int64_t const delta = _rhs.Elapsed - this->Elapsed;
   return ::abs(delta) / static_cast<float>(this->frequency_);
}